package com.endurance.template.impl;

import com.endurance.template.AbstractPayCallbackTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * @Author: sunlin
 * @Date: 2024-05-09 8:53
 * @Version: 1.0
 * @Description:
 */

@Slf4j
@Component("aLiPayCallbackTemplate")
public class ALiPayCallbackTemplate extends AbstractPayCallbackTemplate {

    @Override
    protected HashMap<String, String> verifySignature() {
        log.info("第一步 开始解析支付宝报文...verifySignature() >>>");
        HashMap<String, String> verifySignature = new HashMap<>();
        // 伪代码
        verifySignature.put("price", "1399");
        // 支付状态为1表示支付成功
        verifySignature.put("aliPayStatus", "1");
        log.info("第一步 解析支付宝报文成功...verifySignature() <<<");
        // 解析报文的参数，200则为成功
        verifySignature.put("code", "200");
        return verifySignature;
    }

    @Override
    protected String asyncService(HashMap<String, String> verifySignature) {
        log.info("第三步 执行支付操作", verifySignature);

        String aliPayStatus = verifySignature.get("aliPayStatus");
        if ("1".equals(aliPayStatus)) {
            log.info("订单支付成功...");
        }
        return resultSuccess();
    }

    @Override
    protected String resultFail() {
        log.info("ali_fail");
        return "ali_fail";
    }

    @Override
    protected String resultSuccess() {
        log.info("ali_success");
        return "ali_success";
    }
}
